package com.yanqu.road.logic.pb;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.yanqu.road.entity.dto.CrossPatronsSkill;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.entity.player.UserPatronsSkill;
import com.yanqu.road.entity.union.UnionConstruct;
import com.yanqu.road.entity.union.UnionJoinApply;
import com.yanqu.road.entity.union.cross.*;
import com.yanqu.road.entity.union.trade.UnionTradeLog;
import com.yanqu.road.logic.helper.UnionHelper;
import com.yanqu.road.pb.patrons.PatronsProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.pb.union.UnionTradeProto;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class CrossUnionPb {

    public static CrossUnionProto.CrossUnionTemp.Builder buildCrossUnionTemp(CrossUnionInfo unionInfo){
        CrossUnionProto.CrossUnionTemp.Builder builder = CrossUnionProto.CrossUnionTemp.newBuilder();
        builder.setUnionAliasId(unionInfo.getUnionAliasId());
        builder.setUnionUid(unionInfo.getUnionUid());
        builder.setUnionName(unionInfo.getUnionName());
        builder.setOwnerNickName(unionInfo.getMasterNickName());
        builder.setOwnerUserId(unionInfo.getMasterUserId());
        builder.setMemberCount(unionInfo.getMemberCount());
        builder.setTotalEarnSpeed(unionInfo.getTotalEarnSpeed().toString());
        builder.setExperience(unionInfo.getExperience());
        builder.setMasterVipExp(unionInfo.getVipExp());
        builder.addAllUnionFlag(UnionHelper.getUnionFlag(unionInfo));
        builder.setServerId(unionInfo.getServerId());
        builder.setIsDelete(unionInfo.isDelete());
        builder.setWealth(unionInfo.getWealth());
        builder.setCross(unionInfo.isCross());
        builder.setRankActivityId(unionInfo.getRankActivityId());
        builder.setRankAddExp(unionInfo.getRankAddExp());
        //
        builder.setOutNotice(unionInfo.getOutNotice());
        builder.setInnerNotice(unionInfo.getInnerNotice());
        builder.setWtCode(unionInfo.getWechatCode());
        builder.setQqCode(unionInfo.getQqCode());
        builder.setCreateTime((int) unionInfo.getCreateTime());
        builder.setHonors(unionInfo.getHonors());
        builder.setDeleteCoolingOffTime(unionInfo.getDeleteCoolingOffTime());
        return builder;
    }


    public static CrossUnionProto.CrossUnionMemberTemp.Builder buildCrossUnionMemberTemp(CrossUnionMember member){
        CrossUnionProto.CrossUnionMemberTemp.Builder builder = CrossUnionProto.CrossUnionMemberTemp.newBuilder();
        builder.setUnionUid(member.getUnionUid());
        builder.setUserId(member.getUserId());
        builder.setPosition(member.getPosition());
        builder.setContribution(member.getContribution());
        builder.setTodayContribution(member.getTodayContribution());
        builder.setTotalContribution(member.getTotalContribution());
        builder.setQuitTime(member.getQuitTime());
        builder.setDonateTimes(member.getDonateTimes());
        builder.setConstructRewardIndexList(member.getConstructRewardIndexListString());
        builder.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(member.getUserBaseInfo()));
        builder.setLose(member.getLose());
        builder.setServerId(member.getServerId());
        builder.setChamberPatronsId(member.getChamberPatronsId());
        if(member.getChamberPatrons() != null){
            builder.setChamber(buildCrossUnionChamberPatronsTemp(member.getChamberPatrons()));
        }
        if(!StringUtils.isNullOrEmpty(member.getUnionConstructMapJson())){
            Map<Integer, UnionConstruct> unionConstructMap = JSON.parseObject(member.getUnionConstructMapJson(), new TypeReference<Map<Integer, UnionConstruct>>() {});
            for(UnionConstruct unionConstruct : unionConstructMap.values()){
                UnionProto.UnionConstructTempMsg.Builder constructMsg = parseUnionConstructTempMsg(unionConstruct);
                if(null != constructMsg){
                    builder.addConstructList(constructMsg);
                }
            }
        }
        builder.setHistoryMaxAbility(member.getHistoryMaxAbility().toString());
        return builder;
    }

    public static CrossUnionProto.CrossUnionChamberPatronsTemp.Builder buildCrossUnionChamberPatronsTemp(CrossUnionChamberPatrons chamberPatrons){
        CrossUnionProto.CrossUnionChamberPatronsTemp.Builder builder = CrossUnionProto.CrossUnionChamberPatronsTemp.newBuilder();
        builder.setPatronsId(chamberPatrons.getPatronsId());
        builder.setLevel(chamberPatrons.getLevel());
        builder.setStageLv(chamberPatrons.getStageLv());
        builder.setBreakLv(chamberPatrons.getBreakLv());
        builder.setSkinId(chamberPatrons.getSkinId());
        builder.setPromotionId(chamberPatrons.getPromotionId());
        builder.setAbility(chamberPatrons.getAbility().toString());
        for (CrossPatronsSkill patronsSkill : chamberPatrons.getSkillList()) {
            PatronsProto.PatronsSkillTempMsg.Builder tempMsg = PatronsProto.PatronsSkillTempMsg.newBuilder();
            tempMsg.setSkillId(patronsSkill.getId());
            tempMsg.setSkillLv(patronsSkill.getLv());
            tempMsg.setType(patronsSkill.getType());
            tempMsg.setSkinSkillLevel(patronsSkill.getSkinLv());
            builder.addSkill(tempMsg);
        }
        return builder;
    }

    public static CrossUnionProto.CrossUnionChamberPatronsTemp.Builder buildCrossUnionChamberPatronsTemp(UserPatrons userPatrons){
        CrossUnionProto.CrossUnionChamberPatronsTemp.Builder builder = CrossUnionProto.CrossUnionChamberPatronsTemp.newBuilder();
        builder.setPatronsId(userPatrons.getPatronsId());
        builder.setLevel(userPatrons.getLevel());
        builder.setStageLv(userPatrons.getStageLv());
        builder.setBreakLv(userPatrons.getBreakLv());
        builder.setSkinId(userPatrons.getSkinId());
        builder.setPromotionId(userPatrons.getShowPromotionId());
        builder.setAbility(userPatrons.getAbility().toString());
        for (UserPatronsSkill patronsSkill : userPatrons.getSkillList()) {
            PatronsProto.PatronsSkillTempMsg.Builder tempMsg = PatronsProto.PatronsSkillTempMsg.newBuilder();
            tempMsg.setSkillId(patronsSkill.getSkillId());
            tempMsg.setSkillLv(patronsSkill.getSkillLv());
            tempMsg.setType(patronsSkill.getType());
            tempMsg.setSkinSkillLevel(patronsSkill.getSkinSkillLevel());
            builder.addSkill(tempMsg);
        }
        return builder;
    }

    public static CrossUnionInfo parseCrossUnionInfo(CrossUnionProto.CrossUnionTemp temp){
        CrossUnionInfo unionInfo = new CrossUnionInfo();
        unionInfo.setUnionAliasId(temp.getUnionAliasId());
        unionInfo.setUnionUid(temp.getUnionUid());
        unionInfo.setUnionName(temp.getUnionName());
        unionInfo.setMasterNickName(temp.getOwnerNickName());
        unionInfo.setMasterUserId(temp.getOwnerUserId());
        unionInfo.setMemberCount(temp.getMemberCount());
        unionInfo.setTotalEarnSpeed(new BigInteger(temp.getTotalEarnSpeed()));
        unionInfo.setExperience(temp.getExperience());
        unionInfo.setVipExp(temp.getMasterVipExp());
        if(temp.getUnionFlagCount() > 1){
            unionInfo.setUnionFlagStr(StringUtils.listToString(temp.getUnionFlagList(), StringUtils.SEPARATOR));
        }else {
            unionInfo.setUnionFlag(temp.getUnionFlag(0));
        }
        unionInfo.setAllFlagList(new ArrayList<>(temp.getAllUnionFlagList()));
        unionInfo.setServerId(temp.getServerId());
        unionInfo.setDelete(temp.getIsDelete());
        unionInfo.setWealth(temp.getWealth());
        unionInfo.setCross(temp.getCross());
        if(temp.hasRankActivityId()){
            unionInfo.setRankActivityId(temp.getRankActivityId());
        }
        if(temp.hasRankAddExp()){
            unionInfo.setRankAddExp(temp.getRankAddExp());
        }
        unionInfo.setOutNotice(temp.getOutNotice());
        unionInfo.setInnerNotice(temp.getInnerNotice());
        unionInfo.setWechatCode(temp.getWtCode());
        unionInfo.setQqCode(temp.getQqCode());
        unionInfo.setCreateTime(temp.getCreateTime());
        unionInfo.setHonors(temp.getHonors());
        unionInfo.setDeleteCoolingOffTime(temp.getDeleteCoolingOffTime());
        return unionInfo;
    }

    public static CrossUnionMember parseCrossUnionMember(CrossUnionProto.CrossUnionMemberTemp temp){
        CrossUnionMember member = new CrossUnionMember();
        member.setUnionUid(temp.getUnionUid());
        member.setUserId(temp.getUserId());
        member.setPosition(temp.getPosition());
        member.setContribution(temp.getContribution());
        member.setTodayContribution((int)temp.getTodayContribution());
        member.setTotalContribution(temp.getTotalContribution());
        member.setQuitTime(temp.getQuitTime());
        member.setDonateTimes(temp.getDonateTimes());
        member.setConstructRewardIndexList(StringUtils.stringToIntegerList(temp.getConstructRewardIndexList(), ","));
        member.setUserBaseInfo(PlayerBasePb.parseToUserBaseInfo(temp.getPlayerBaseData()));
        member.setLose(temp.getLose());
        member.setServerId(temp.getServerId());
        member.setChamberPatronsId(temp.getChamberPatronsId());
        if(temp.hasChamber()){
            CrossUnionChamberPatrons chamberPatrons = parseCrossUnionChamberPatrons(temp.getChamber());
            chamberPatrons.setUserId(member.getUserId());
            member.setChamberPatrons(chamberPatrons);
        }
        for (UnionProto.UnionConstructTempMsg constructTempMsg : temp.getConstructListList()) {
            UnionConstruct construct = new UnionConstruct();
            construct.setConstructType(constructTempMsg.getConstructType());
            construct.setTimes(constructTempMsg.getTimes());
            construct.setLastConstructTime(constructTempMsg.getLastConstructTime());
            member.getUnionConstructMap().put(construct.getConstructType(), construct);
        }
        BigInteger historyMaxAbility = BigInteger.ZERO;
        if(!StringUtils.isNullOrEmpty(temp.getHistoryMaxAbility())){
            historyMaxAbility = new BigInteger(temp.getHistoryMaxAbility());
        }
        member.setHistoryMaxAbility(historyMaxAbility);
        return member;
    }

    public static CrossUnionChamberPatrons parseCrossUnionChamberPatrons(CrossUnionProto.CrossUnionChamberPatronsTemp temp){
        CrossUnionChamberPatrons patrons = new CrossUnionChamberPatrons();
        patrons.setPatronsId(temp.getPatronsId());
        patrons.setLevel(temp.getLevel());
        patrons.setStageLv(temp.getStageLv());
        patrons.setBreakLv(temp.getBreakLv());
        patrons.setSkinId(temp.getSkinId());
        patrons.setPromotionId((int)temp.getPromotionId());
        patrons.setAbility(new BigInteger(temp.getAbility()));
        for (PatronsProto.PatronsSkillTempMsg tempMsg : temp.getSkillList()) {
            patrons.getSkillList().add(new CrossPatronsSkill(tempMsg.getSkillId(), tempMsg.getSkillLv(), tempMsg.getType(), tempMsg.getSkinSkillLevel()));
        }
        return patrons;
    }

    public static UnionProto.UnionDetailMsg.Builder parseUnionDetailMsg(String unionUid, CrossUnionInfo unionInfo, List<CrossUnionMember> memberList, int syncType, List<CrossUnionFlag> flagList){
        UnionProto.UnionDetailMsg.Builder msg = UnionProto.UnionDetailMsg.newBuilder();
        msg.setType(syncType);
        msg.setUnionUid(unionUid);
        UnionProto.UnionTempMsg.Builder unionMsg = parseUnionTempMsg(unionInfo);
        if(null != unionMsg){
            msg.setUnionInfo(unionMsg);
        }
        if(null != memberList){
            for(CrossUnionMember unionMember : memberList){
                UnionProto.UnionMemberTempMsg.Builder memberMsg = parseUnionMemberTempMsg(unionMember);
                if(null != memberMsg){
                    memberMsg.setServerId(unionMember.getServerId());
                    msg.addMemberList(memberMsg);
                }
            }
        }
        if (flagList != null) {
            for (CrossUnionFlag flag : flagList) {
                msg.addFlag(parseFlagMsg(flag));
            }
        }
        if (null != unionInfo) {
            for (Map.Entry<Integer, Integer> gradeEntry : unionInfo.getGradeAmountMap().entrySet()) {
                msg.addOriginalGradeAmount(UnionProto.UnionRankGradeJoinLimitTemp.newBuilder().setGradeId(gradeEntry.getKey()).setNum(gradeEntry.getValue()));
            }
        }


        return msg;
    }

    public static UnionProto.UnionFlagMsg.Builder parseFlagMsg(CrossUnionFlag flag) {
        UnionProto.UnionFlagMsg.Builder msg = UnionProto.UnionFlagMsg.newBuilder();
        msg.setFlagId(flag.getFlagId());
        msg.setExpiredTime(DateHelper.toSecond(flag.getExpireTime()));
        msg.setRead(flag.isRead());
        return msg;
    }

    public static UnionProto.UnionTempMsg.Builder parseUnionTempMsg(CrossUnionInfo unionInfo){
        if(null == unionInfo){
            return null;
        }
        UnionProto.UnionTempMsg.Builder msg = UnionProto.UnionTempMsg.newBuilder();
        msg.setUnionUid(unionInfo.getUnionUid());
        msg.setUnionName(unionInfo.getUnionName());
        msg.addAllUnionFlag(UnionHelper.getUnionFlag(unionInfo));
        msg.setExperience(unionInfo.getExperience());
        msg.setOutNotice(unionInfo.getOutNotice());
        msg.setIsAllowRandomJoin(unionInfo.isAllowRandomJoin());
        msg.setInnerNotice(unionInfo.getInnerNotice());
        msg.setWtCode(unionInfo.getWechatCode());
        msg.setQqCode(unionInfo.getQqCode());
        msg.setOwnerUserId(unionInfo.getMasterUserId());
        msg.setOwnerNickName(unionInfo.getMasterNickName());
        msg.setWealth(unionInfo.getWealth());
        msg.setMemberCount(unionInfo.getMemberCount());
        msg.setTotalEarnSpeed(unionInfo.getTotalEarnSpeed().toString());
        msg.setIsDelete(unionInfo.isDelete());
        msg.setFlagModifyTime(unionInfo.getFlagModifyTime());
        msg.setConstructActive(unionInfo.getConstructActive());
        msg.setUnionAliasId(unionInfo.getUnionAliasId());
        msg.setApplyTitleLimit(unionInfo.getApplyTitleLimit());
        msg.setServerId(unionInfo.getServerId());
        msg.setCross(unionInfo.isCross());
        msg.setHonerPoint(unionInfo.getHonors());
        msg.setDayJoinNum(unionInfo.getDayJoinNum());
        msg.setDeleteCoolingOffTime(unionInfo.getDeleteCoolingOffTime());
        return msg;
    }

    public static UnionProto.UnionMemberTempMsg.Builder parseUnionMemberTempMsg(CrossUnionMember unionMember){
        if(null == unionMember){
            return null;
        }
        UnionProto.UnionMemberTempMsg.Builder msg = UnionProto.UnionMemberTempMsg.newBuilder();
        msg.setUnionUid(unionMember.getUnionUid());
        msg.setPosition(unionMember.getPosition());
        msg.setUserId(unionMember.getUserId());
        msg.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(unionMember.getUserBaseInfo()));
        msg.setContribution(unionMember.getContribution());
        msg.setTotalContribution(unionMember.getTotalContribution());
        msg.setDonateTimes(unionMember.getDonateTimes());
        msg.setQuitTime(unionMember.getQuitTime());
        msg.addAllApplyUnionUidList(StringUtils.stringToStringList(unionMember.getApplyUnionUidListString(), ","));
        for (Map.Entry<Integer, UnionConstruct> constructEntry : unionMember.getUnionConstructMap().entrySet()) {
            UnionConstruct unionConstruct = constructEntry.getValue();
            UnionProto.UnionConstructTempMsg.Builder constructMsg = parseUnionConstructTempMsg(unionConstruct);
            if(null != constructMsg){
                msg.addConstructList(constructMsg);
            }
        }
        msg.setTodayContribution(unionMember.getTodayContribution());
        msg.addAllConstructRewardIndexList(StringUtils.stringToIntegerList(unionMember.getConstructRewardIndexListString(), ","));
        msg.setNoticeReadState(unionMember.getNoticeReadState());
        msg.setHistoryMaxAbility(unionMember.getHistoryMaxAbility().toString());
        msg.setMonthAbilityRank(unionMember.getMonthAbilityRank());
        msg.setMonthAbilityRankGrade(unionMember.getAbilityRankGrade());
        return msg;
    }

    public static UnionProto.UnionConstructTempMsg.Builder parseUnionConstructTempMsg(UnionConstruct unionConstruct){
        if(null == unionConstruct){
            return null;
        }
        UnionProto.UnionConstructTempMsg.Builder msg = UnionProto.UnionConstructTempMsg.newBuilder();
        msg.setConstructType(unionConstruct.getConstructType());
        msg.setTimes(unionConstruct.getTimes());
        msg.setLastConstructTime(unionConstruct.getLastConstructTime());
        return msg;
    }

    public static UnionProto.UnionJoinApplyListMsg.Builder parseUnionJoinApplyListMsg(List<UnionJoinApply> unionJoinApplyList){
        UnionProto.UnionJoinApplyListMsg.Builder listMsg = UnionProto.UnionJoinApplyListMsg.newBuilder();
        if(null != unionJoinApplyList){
            for(UnionJoinApply unionJoinApply : unionJoinApplyList){
                UnionProto.UnionJoinApplyTempMsg.Builder msg = parseUnionJoinApplyTempMsg(unionJoinApply);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static UnionProto.UnionJoinApplyTempMsg.Builder parseUnionJoinApplyTempMsg(UnionJoinApply unionJoinApply){
        if(null == unionJoinApply){
            return null;
        }
        UnionProto.UnionJoinApplyTempMsg.Builder msg = UnionProto.UnionJoinApplyTempMsg.newBuilder();
        msg.setUserId(unionJoinApply.getUserId());
        PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(unionJoinApply.getUserBaseInfo());
        msg.setPlayerBaseData(baseMsg);
        msg.setApplyTime(unionJoinApply.getApplyTime());
        msg.setIsDelete(unionJoinApply.isDelete());
        msg.setRankGrade(unionJoinApply.getRankGrade());
        return msg;
    }

    public static UnionProto.UnionNoticeListMsg.Builder parseUnionNoticeListMsg(List<CrossUnionNotice> unionNoticeList){
        UnionProto.UnionNoticeListMsg.Builder listMsg = UnionProto.UnionNoticeListMsg.newBuilder();
        if(null != unionNoticeList){
            for(CrossUnionNotice unionNotice : unionNoticeList){
                UnionProto.UnionNoticeTempMsg.Builder msg = parseUnionNoticeTempMsg(unionNotice);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static UnionProto.UnionNoticeTempMsg.Builder parseUnionNoticeTempMsg(CrossUnionNotice unionNotice){
        if(null == unionNotice){
            return null;
        }
        UnionProto.UnionNoticeTempMsg.Builder msg = UnionProto.UnionNoticeTempMsg.newBuilder();
        msg.setType(unionNotice.getType());
        msg.setUserId(unionNotice.getUserId());
        msg.setNickName(unionNotice.getNickName());
        msg.setNoticeTime(unionNotice.getNoticeTime());
        msg.setContent(unionNotice.getContent());
        return msg;
    }

    public static CrossUnionChamberPatrons parseCrossUnionChamberPatrons(long userId, CrossUnionProto.CrossUnionChamberPatronsTemp patronsTemp){
        CrossUnionChamberPatrons patrons = new CrossUnionChamberPatrons();
        patrons.setUserId(userId);
        patrons.setPatronsId(patronsTemp.getPatronsId());
        patrons.setAbility(new BigInteger(patronsTemp.getAbility()));
        patrons.setLevel(patronsTemp.getLevel());
        patrons.setStageLv(patronsTemp.getStageLv());
        patrons.setBreakLv(patronsTemp.getBreakLv());
        patrons.setSkinId(patronsTemp.getSkinId());
        patrons.setPromotionId((int)patronsTemp.getPromotionId());
        for (PatronsProto.PatronsSkillTempMsg skillTempMsg : patronsTemp.getSkillList()) {
            CrossPatronsSkill skill = new CrossPatronsSkill();
            skill.setId(skillTempMsg.getSkillId());
            skill.setLv(skillTempMsg.getSkillLv());
            skill.setType(skillTempMsg.getType());
            skill.setSkinLv(skillTempMsg.getSkinSkillLevel());
            patrons.getSkillList().add(skill);
        }
        return patrons;
    }


    //cross

    public static UnionProto.UnionChamberPatronsListMsg.Builder parseCrossUnionChamberPatronsListMsg(List<CrossUnionChamberPatrons> userPatronsList){
        UnionProto.UnionChamberPatronsListMsg.Builder listMsg = UnionProto.UnionChamberPatronsListMsg.newBuilder();
        if(null != userPatronsList){
            for(CrossUnionChamberPatrons userPatrons : userPatronsList){
                UnionProto.UnionChamberPatronsTempMsg.Builder msg = parseCrossUnionChamberPatronsTempMsg(userPatrons.getUserId(), false, userPatrons);
                listMsg.addDataList(msg);
            }
        }
        return listMsg;
    }

    public static UnionProto.UnionChamberPatronsTempMsg.Builder parseCrossUnionChamberPatronsTempMsg(long userId, boolean isRemove, CrossUnionChamberPatrons userPatrons){
        UnionProto.UnionChamberPatronsTempMsg.Builder msg = UnionProto.UnionChamberPatronsTempMsg.newBuilder();
        msg.setUserId(userId);
        msg.setIsRemove(isRemove);
        PatronsProto.PatronsTempMsg.Builder patronsMsg = parsePatronsTempMsg(userPatrons);
        if(null != patronsMsg){
            msg.setPatronsData(patronsMsg);
            msg.setPatronsAbility(userPatrons.getAbility().toString());
        }
        return msg;
    }

    private static PatronsProto.PatronsTempMsg.Builder parsePatronsTempMsg(CrossUnionChamberPatrons userPatrons) {
        if(userPatrons == null){
            return null;
        }
        PatronsProto.PatronsTempMsg.Builder builder = PatronsProto.PatronsTempMsg.newBuilder();
        builder.setPatronsId(userPatrons.getPatronsId());
        builder.setLevel(userPatrons.getLevel());
        builder.setStageLv(userPatrons.getStageLv());
        builder.setBreakLv(userPatrons.getBreakLv());
        builder.setSkinId(userPatrons.getSkinId());
        builder.setPromotionId(userPatrons.getPromotionId());
        //todo
        builder.setTradeWarAddEarnSpeed("0");
        builder.setAddAbility(userPatrons.getAbility().toString());
        for (CrossPatronsSkill skill : userPatrons.getSkillList()) {
            PatronsProto.PatronsSkillTempMsg.Builder skillBuilder = PatronsProto.PatronsSkillTempMsg.newBuilder();
            skillBuilder.setSkillId(skill.getId());
            skillBuilder.setSkillLv(skill.getLv());
            skillBuilder.setType(skill.getType());
            skillBuilder.setSkinSkillLevel(skill.getSkinLv());
            builder.addSkillList(skillBuilder);
        }
        return builder;
    }

    public static List<UnionTradeProto.TradeLogDataTempMsg> parseTradeLogDataTempMsgList(List<UnionTradeLog> logDataList) {
        List<UnionTradeProto.TradeLogDataTempMsg> builderList = new ArrayList<>();
        for (UnionTradeLog tradeLogData : logDataList) {
            UnionTradeProto.TradeLogDataTempMsg.Builder logDataMsg = UnionTradeProto.TradeLogDataTempMsg.newBuilder();
            logDataMsg.setAddTime(tradeLogData.getAddTime());
            logDataMsg.addAllParams(tradeLogData.getLogParamsList());
            logDataMsg.setEventId(tradeLogData.getEventId());
            builderList.add(logDataMsg.build());
        }
        return  builderList;
    }

    public static UnionProto.UnionRankGradeJoinLimitTemp.Builder parseUnionRankGradeJoinLimitTemp(int gradeId, int num){
        UnionProto.UnionRankGradeJoinLimitTemp.Builder msg = UnionProto.UnionRankGradeJoinLimitTemp.newBuilder();
        msg.setGradeId(gradeId);
        msg.setNum(num);
        return msg;
    }
}
